﻿namespace OA.DAL.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class roleaction : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.SysRoles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                        Remark = c.String(nullable: false, maxLength: 20),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SysActions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 20),
                        ParentId = c.Int(nullable: false),
                        ControllerName = c.String(maxLength: 20),
                        ActionName = c.String(maxLength: 20),
                        Method = c.String(maxLength: 20),
                        Url = c.String(maxLength: 50),
                        Icon = c.String(maxLength: 20),
                        IsMenu = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SysActionSysRoles",
                c => new
                    {
                        SysAction_Id = c.Int(nullable: false),
                        SysRole_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.SysAction_Id, t.SysRole_Id })
                .ForeignKey("dbo.SysActions", t => t.SysAction_Id, cascadeDelete: true)
                .ForeignKey("dbo.SysRoles", t => t.SysRole_Id, cascadeDelete: true)
                .Index(t => t.SysAction_Id)
                .Index(t => t.SysRole_Id);
            
            CreateTable(
                "dbo.SysRoleSysPersons",
                c => new
                    {
                        SysRole_Id = c.Int(nullable: false),
                        SysPerson_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.SysRole_Id, t.SysPerson_Id })
                .ForeignKey("dbo.SysRoles", t => t.SysRole_Id, cascadeDelete: true)
                .ForeignKey("dbo.Sys_Person", t => t.SysPerson_Id, cascadeDelete: true)
                .Index(t => t.SysRole_Id)
                .Index(t => t.SysPerson_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.SysRoleSysPersons", "SysPerson_Id", "dbo.Sys_Person");
            DropForeignKey("dbo.SysRoleSysPersons", "SysRole_Id", "dbo.SysRoles");
            DropForeignKey("dbo.SysActionSysRoles", "SysRole_Id", "dbo.SysRoles");
            DropForeignKey("dbo.SysActionSysRoles", "SysAction_Id", "dbo.SysActions");
            DropIndex("dbo.SysRoleSysPersons", new[] { "SysPerson_Id" });
            DropIndex("dbo.SysRoleSysPersons", new[] { "SysRole_Id" });
            DropIndex("dbo.SysActionSysRoles", new[] { "SysRole_Id" });
            DropIndex("dbo.SysActionSysRoles", new[] { "SysAction_Id" });
            DropTable("dbo.SysRoleSysPersons");
            DropTable("dbo.SysActionSysRoles");
            DropTable("dbo.SysActions");
            DropTable("dbo.SysRoles");
        }
    }
}
